1. SSPCON (Synchronous Serial Port Control Register)
Controls and configures the SPI engine.
Key Bits:
-
SSPOV (Overflow Flag):
- Set when new SPI data arrives before the previous
SSPBUFwas read. - Indicates overflow error – data may be lost.
- Must be cleared by software and the SSP module reset (toggle
SSPEN) before further use.
- Set when new SPI data arrives before the previous
-
SSPEN (Enable Bit):
1→ Enables the SSP (SPI) module (must remain set during use).0→ Disables or resets the module.
-
CKP (Clock Polarity):
- Sets the idle state of the clock (CPOL).
0→ Clock idles LOW1→ Clock idles HIGH
2. SSPSTAT (Synchronous Serial Port Status Register)
Provides status and configuration options for SPI transfers.
Key Bits:
-
SMP (Sample Timing):
- Slave Mode: Must remain cleared.
- Master Mode: Selects when data is sampled:
0→ Sample in the middle of output data1→ Sample at the end of output data
- Allows compatibility with different SPI slaves.
-
CKE (Clock Edge Select):
- Determines on which edge data is transmitted/received (affects CPHA).
- Works together with CKP to set SPI mode (0–3).
-
BF (Buffer Full):
1→SSPBUFcontains unread data.- Must read
SSPBUFbefore new data arrives to prevent overflow. - Automatically cleared when
SSPBUFis read.
Important Notes:
-
Overflow Handling:
- If
SSPOV = 1, it means data was lost. - Software must:
- Clear
SSPOV. - Toggle
SSPENto reset the module. - Ensure
SSPOVremains cleared before continuing.
- Clear
- If
-
Good Practice:
- Always check BF before writing/reading.
- Clear SSPOV if set, otherwise SPI data may stop updating.